const http = require("http")
const handleUserRequest= require("./views/user")
const handleGoodsRequest= require("./views/goods")
const handleChannelRequest= require("./views/channel")

const server = http.createServer(
    (req, res) => {
        res.setHeader("Content-Type","application/json;charset=utf8;")
        switch (true) {
            case req.url.startsWith("/user/"):
                handleUserRequest(req,res)
                break;
            case req.url.startsWith("/goods/"):
                handleGoodsRequest(req,res)
                break;
            case req.url.startsWith("/channel/"):
                handleChannelRequest(req,res)
                break;
            default:
                res.end("404")
                break;
        }
    }
)
server.listen(8001, () => {
    console.log("server is listening at 8001...");
})